package com.song.tools.log.operatelog.config;

import com.song.tools.log.operatelog.aspect.OperateLogAspect;
import com.song.tools.log.operatelog.service.DefaultOperateLogProcessor;
import com.song.tools.log.operatelog.service.OperateLogProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;

/**
 * 操作日志自动配置
 *
 * @author song tools
 * @since 2024-07-03
 */
@Configuration
@Slf4j
@ConditionalOnProperty(name = {"log-tool.log.operate.enable"}, havingValue = "true")
@EnableConfigurationProperties({OperateLogProperties.class})
@Import(ThreadPoolConfiguration.class)
public class OperateLogAutoConfiguration implements InitializingBean {


    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("操作日志自动化配置完成");
    }


    @Order
    @Bean
    @ConditionalOnMissingBean(OperateLogProcessor.class)
    public OperateLogProcessor operateLogProcessor() {
        return new DefaultOperateLogProcessor();
    }

    @Order(100)
    @Bean
    @ConditionalOnMissingBean(OperateLogAspect.class)
    public OperateLogAspect operateLogAspect() {
        return new OperateLogAspect();
    }
}
